<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BasePatientNotes {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_intCasePaperId;
	protected $m_intNoteTypeId;
	protected $m_intReferenceId;
	protected $m_strDescription;
	protected $m_strMedicalDetails;
	protected $m_intDoctorId;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getCasePaperId(){
		return $this->m_intCasePaperId;
	}

	public function getNoteTypeId(){
		return $this->m_intNoteTypeId;
	}

	public function getReferenceId(){
		return $this->m_intReferenceId;
	}

	public function getDescription(){
		return $this->m_strDescription;
	}

	public function getMedicalDetails(){
		return $this->m_strMedicalDetails;
	}

	public function getDoctorId(){
		return $this->m_intDoctorId;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setCasePaperId( $CasePaperId ){
		$this->m_intCasePaperId = $CasePaperId;
	}

	public function setNoteTypeId( $NoteTypeId ){
		$this->m_intNoteTypeId = $NoteTypeId;
	}

	public function setReferenceId( $ReferenceId ){
		$this->m_intReferenceId = $ReferenceId;
	}

	public function setDescription( $Description ){
		$this->m_strDescription = $Description;
	}

	public function setMedicalDetails( $MedicalDetails ){
		$this->m_strMedicalDetails = $MedicalDetails;
	}

	public function setDoctorId( $DoctorId ){
		$this->m_intDoctorId = $DoctorId;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into PATIENT_NOTES (patient_id, case_paper_id, note_type_id, reference_id, description, medical_details, doctor_id, created_by, created_on, updated_by, updated_on) values (" . $this->getPatientId() . ", " . $this->getCasePaperId() . ", " . $this->getNoteTypeId() . ", " . $this->getReferenceId() . ", '" . $this->getDescription() . "', '" . $this->getMedicalDetails() . "', " . $this->getDoctorId() . ", " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE PATIENT_NOTES set  patient_id= " . $this->getPatientId() . ", case_paper_id= " . $this->getCasePaperId() . ", note_type_id= " . $this->getNoteTypeId() . ", reference_id= " . $this->getReferenceId() . ", description= '" . $this->getDescription() . "', medical_details= '" . $this->getMedicalDetails() . "', doctor_id= " . $this->getDoctorId() . ", created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM patient_notes WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'patient_notes'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}